{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "我的外号是大西瓜\n",
      "p\n"
     ]
    }
   ],
   "source": [
    "str1 = \"hello python\"\n",
    "str2 = \"我的外号是大西瓜\"\n",
    "\n",
    "print(str2)\n",
    "print(str1[6])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "我的外号是大西瓜"
     ]
    }
   ],
   "source": [
    "for char in str2:\n",
    "    print(char,end='')"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "data": {
      "text/plain": "11"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hello_str = \"hello hello\"\n",
    "\n",
    "# 1.统计字符串的长度\n",
    "len(hello_str)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "data": {
      "text/plain": "2"
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2.统计某一个子字符串的个数\n",
    "hello_str.count(\"hello\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "data": {
      "text/plain": "2"
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3.某一个子字符串出现的位置\n",
    "hello_str.index(\"llo\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "data": {
      "text/plain": "True"
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "space_str = \" \\t\\n\\r\"\n",
    "\n",
    "# 1.判断空白字符\n",
    "space_str.isspace()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "data": {
      "text/plain": "True"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hello_str = \"hello hello\"\n",
    "\n",
    "# 1.判断是否以指定字符开始\n",
    "hello_str.startswith(\"h\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [
    {
     "data": {
      "text/plain": "True"
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2.判断是否以指定字符结束\n",
    "hello_str.endswith('o')"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "data": {
      "text/plain": "2"
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3.查找指定字符串\n",
    "hello_str.find('llo')"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "data": {
      "text/plain": "'heaa heaa'"
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 4.替换字符串\n",
    "hello_str.replace(\"llo\",\"aa\",2)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "|    登鹳雀楼   |\n",
      "|    王之涣    |\n",
      "|   白日依山尽   |\n",
      "|   黄河入海流   |\n",
      "|   欲穷千里目   |\n",
      "|   更上一层楼   |\n"
     ]
    }
   ],
   "source": [
    "# 假设：以下内容是从网络上抓取的\n",
    "# 要求：顺序并且居中对齐输出以下内容\n",
    "poem = [\"\\t\\n登鹳雀楼\",\n",
    "        \"王之涣\",\n",
    "        \"白日依山尽\\t\\n\",\n",
    "        \"黄河入海流\",\n",
    "        \"欲穷千里目\",\n",
    "        \"更上一层楼\"]\n",
    "for i in poem:\n",
    "    print(\"|%s|\"%i.strip().center(11))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['登鹳雀楼', '王之涣', '白日依山尽', '黄河入海流', '欲穷千里目', '更上一层楼']\n",
      "登鹳雀楼 王之涣 白日依山尽 黄河入海流 欲穷千里目 更上一层楼\n"
     ]
    }
   ],
   "source": [
    "# 1.将字符串中的空白字符全部去掉\n",
    "# 2.使用“”作为分隔符，拼接成一个整齐的字符串\n",
    "poem_str = \"登鹳雀楼\\t,王之涣 \\t,白日依山尽 \\t \\n,黄河入海流 \\t\\t,欲穷千里目 \\t\\t\\n,更上一层楼\"\n",
    "p1 = poem_str.replace(\",\",\" \")\n",
    "poem_list = p1.split()\n",
    "print(poem_list)\n",
    "result = \" \".join(poem_list)\n",
    "print(result)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}